package com.shengwei.truck.driver.view.adapter.task;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.shengwei.truck.driver.R;
import com.shengwei.truck.driver.bean.FileUrlBean;

import java.util.List;

public class TaskGridAdapter extends BaseAdapter {
    private List<FileUrlBean> mDataList;
    private Context mContext;

    public TaskGridAdapter(Context context, List<FileUrlBean> dataList) {
        this.mContext = context;
        this.mDataList = dataList;
    }
    public int getCount() {
        if(mDataList != null){
            return mDataList.size();
        }
        return 0;
    }
    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_publish, null);
            holder = new ViewHolder();
            holder.imvPounds = (ImageView) convertView.findViewById(R.id.item_grid_image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String photoThumbUrl = mDataList.get(position).getThumbFileUrl();
        Glide.with(convertView.getContext()).load(photoThumbUrl).into(holder.imvPounds);
        return convertView;
    }
    class ViewHolder {
        ImageView imvPounds;
    }
}
